#include "StdAfx.h"
#include "SessionEventHandler.h"
#include <Windows.h>

using namespace utility::network;
void CSessionEventHandler::on_established()
{
    cout<<"established from ip "<<m_pConnector->get_session()->get_remote_ip_as_string()
        <<"port "<<m_pConnector->get_session()->get_remote_port()<<endl;
}

void CSessionEventHandler::on_disconnected()
{
    cout<<"disconnected from ip "<<m_pConnector->get_session()->get_remote_ip_as_string()<<endl;
}

void CSessionEventHandler::on_error(int32 error_code, const char *error_message)
{
    cout<<"error occurred with id="<<error_code<<", message="<<error_message<<endl;
    if (error_code == 10061 || error_code == 10054)
    {
        Sleep(1000);
        m_pConnector->reconnect(0);
    }
}

void CSessionEventHandler::on_receive(const char *message, uint32 message_length)
{
    cout<<"receive message :"<<message<<endl;
}

void CSessionEventHandler::SetConnector(const utility::network::connector * pConnector)
{
    m_pConnector = const_cast<connector*>(pConnector);
}
